<?php
require(dirname(dirname(__FILE__)).'/libs/db.class.php');
class Setting{
    public $db;
    function __construct()
    {
        $this->db=new DB();
    }

    /*
        获取系统配置
    */ 
    function index(){
        $output=['errcode'=>0,'msg'=>'success'];
        $sql="select * from site_settings where id=1";
        $res=$this->db->get_one($sql);
        if($res){
            $output['data']=$res;
        }else{
            $output['errcode']=1;
            $output['msg']='操作失败';
        }
        echo json_encode($output);
    }

    /*
        更新系统配置
    */ 
    function update(){
        $output=['errcode'=>0,'msg'=>'success'];
        if($_POST){
            $data=$_POST;
            $query_str=arr2str($data);
            $sql="update site_settings set {$query_str} where id=1";
            $res=$this->db->get_one($sql);
            if($res){
                $output['data']=$res;
            }else{
                $output['errcode']=1;
                $output['msg']='操作失败';
            }
        }else{

        }
        echo json_encode($output);
    }


}
?>